<?php

// plugin
// name: Picture

class Video {
	
	private		$id;
	private		$link;
	private		$source;
	
	// functions
	
	function __construct($i=NULL) {
		
		if (!$i) {
			throw new Exception("Couldn't create Video.");
		}
		
		$this->id = $i;
		
		if($helpArray = $this->getfromdb($this->id)) {
			$this->link = $helpArray["link"];
			$this->source = $helpArray["source"];
		}
		
	}
	
	public function getfromdb($number) {
		$q = "SELECT link, source FROM videos WHERE videos.id = " . $number;
		$r = mysql_query("set names 'utf8'");
		$r = mysql_query($q);
		if (mysql_num_rows($r)) {
			return (mysql_fetch_array($r));
		}
		else {
			return (NULL);
		}
	}
	
	function show() {
		switch($this->source) {
			case "vimeo" : echo '<iframe src="http://player.vimeo.com/video/'. $this->link .'" width="620" height="310" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; break;
			case "youtube" : echo '<iframe width="620" height="520" src="http://www.youtube.com/embed/'. $this->link .'" frameborder="0" allowfullscreen></iframe>'; break;
		}
	}
	
}

?>